package com.yuwei.service;

import com.yuwei.bean.SysUser;
import com.yuwei.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SysUserService {

    @Autowired
    BCryptPasswordEncoder bCryptPasswordEncoder;

    /**
     * 账号 获取用户信息
     * @param username
     * @return
     */
    public SysUser selectByUsername(String username) {
        SysUser sysUser = new SysUser();
        sysUser.setId("111");
        sysUser.setUsername("zhangsan");
        //加密
        sysUser.setPassword(bCryptPasswordEncoder.encode("123456"));
        return sysUser;
    }


    /**
     * 用户id查询所有角色
     * @param id
     * @return
     */
    public List<String> selectRolesByUser(String id) {
        List<String> roles = new ArrayList<>();
        roles.add("user1");
//        roles.add("user2");
        return roles;
    }


    /**
     * 获取所有权限uri
     * @return
     */
    public Map<String, List<String>> selectPermissions() {

        Map<String, List<String>> data = new HashMap<>();
        List<String> user1Permissions = new ArrayList<>();
        user1Permissions.add("/user1/a");
        user1Permissions.add("/user1/b");
        user1Permissions.add("/user1/c");
        data.put("user1", user1Permissions);

        List<String> user2Permissions = new ArrayList<>();
        user2Permissions.add("/user2/a");
        user2Permissions.add("/user2/b");
        user2Permissions.add("/user2/c");
        data.put("user2", user2Permissions);
        return data;
    }


}
